import pandas as pd
import sys
import os

def process_excel(input_path, output_path):
    try:
        df = pd.read_excel(input_path)
        # 检查必要列是否存在
        required_columns = ['sku', 'date', 'qty']
        if not all(col in df.columns for col in required_columns):
            return {'status': 'error', 'message': 'Excel文件缺少必要列头'}
        
        # 按sku汇总qty
        result = df.groupby('sku')['qty'].sum().reset_index()
        
        # 确保输出目录存在
        os.makedirs(os.path.dirname(output_path), exist_ok=True)
        
        # 保存结果
        result.to_excel(output_path, index=False)
        return {'status': 'success', 'path': output_path}
    except Exception as e:
        return {'status': 'error', 'message': str(e)}

if __name__ == '__main__':
    if len(sys.argv) != 3:
        print("Usage: python main.py <input_path> <output_path>")
        sys.exit(1)
    
    input_file = sys.argv[1]
    output_file = sys.argv[2]
    process_result = process_excel(input_file, output_file)
    print(process_result)